package class_1_16;

import java.util.ArrayList;
import java.util.Arrays;

class Student{
   int age;
   String  name;
   Student(int age,String  name){
       this.age=age;
       this.name=name;
   }
     //当前对象和传入的obj相比
     public boolean equals(Object obj){
       //1.判断obj对象是否为空
       if(obj==null){
           return false;
       }
       //2.判断obj是否就是自己
       if(obj == this){
          return true;
       }
       //3.判断obj是否是Student类对象
         if(!(obj instanceof Student)){
             return false;
         }
         //4.obj一定是Student类的对象而且与当前对象不是同一个地址
         //向下转型为Student，比较当前对象的属性值和传入对象的属性
         Student stu=(Student) obj;
         return this.name.equals(stu.name)&&this.age== stu.age;
   }

     @Override
   public String toString() {
       return "Student{" +
               "age=" + age +
               ", name=" + name +
               '}';
   }
}
interface IMessage{
    void printMsg();
}
class MessageImpl implements IMessage{
    @Override
    public void printMsg(){
        System.out.println("今天超级开心~因为我当姑姑了");
    }
}
public class ObjectTest {
    public static void main(String[] args) {
        //数组引用
        int[] data={1,3,5,7,9};
        //接口引用
        IMessage msg=new MessageImpl();
        //向上转型
        Object obj=data;
        Object obj1=msg;
        //向下转型
        int[] ret=(int[]) obj;
        IMessage test=(IMessage) obj1;
        System.out.println(Arrays.toString(ret));
        test.printMsg();
    }
}